package util

import (
	"encoding/json"
	"fmt"
	"github.com/sirupsen/logrus"
	"io/ioutil"
	"net/http"
	"strings"
)

func HttpGet(url, params, obj interface{}) (interface{}, error) {
	resp, err := http.Get("http://ip.gs/json")
	if err != nil {
		logrus.Info(err)
	}

	defer resp.Body.Close()
	body, err := ioutil.ReadAll(resp.Body)
	if err != nil {
		logrus.Error(err)
	}
	//logger.Info(string(body))
	fmt.Println(string(body))
	return json.Unmarshal(body, obj), err
}
func HttpPost() (string, error) {
	resp, err := http.Post("http://www.baidu.com",
		"application/x-www-form-urlencoded",
		strings.NewReader("name=cjb"))
	if err != nil {
		//logger.Info(err)
	}
	defer resp.Body.Close()
	body, err := ioutil.ReadAll(resp.Body)
	fmt.Println(string(body))
	return string(body), err
}
